package com.fm.base.json.impl;

import com.fm.base.json.JsonArray;
import com.fm.base.json.JsonValue;

import java.math.BigDecimal;
import java.util.ArrayList;

/**
 * @author finalmachine
 */
public class BasicJsonArray extends ArrayList<javax.json.JsonValue> implements JsonArray {
    @Override
    public boolean add(String string) {
        return add(new BasicJsonString(string));
    }

    @Override
    public boolean add(Number number) {
        if (number instanceof BigDecimal) {
            return add(new BasicJsonNumber((BigDecimal) number));
        } else {
            return add(new BasicJsonNumber(number.toString()));
        }
    }

    @Override
    public boolean add(boolean b) {
        return add(new BasicJsonBoolean(b));
    }

    @Override
    public boolean add(javax.json.JsonValue jsonValue) {
        return super.add((JsonValue) jsonValue);
    }

    @Override
    public ValueType getValueType() {
        return ValueType.ARRAY;
    }

    @Override
    public BasicJsonArray clone() {
        BasicJsonArray clone = new BasicJsonArray();
        for (javax.json.JsonValue value : this) {
            clone.add(((JsonValue) value).clone());
        }
        return clone;
    }
}
